$(document).ready(function(){

	flip = 0;
	smallMenu = false;

	movePicture();
	window.setInterval(AnimateRotate, 5000);
	ssc_init();

	/////////// Loader//////////////

	$(window).load(function(){
	  $('#loader').delay(1000).fadeOut(500);
	});

	/////////// Fluid Gallery Tiles//////////////

	var width = $('.tile-sq').width();
	$('.tile-sq').css({'height':width+'px'});
	$('.tile-rect').css({'height':width+'px'});

	$( window ).resize(function() {
		var width = $('.tile-sq').width();
		$('.tile-sq').css({'height':width+'px'});
		$('.tile-rect').css({'height':width+'px'});
	});

	/////////// Show/Hide Small Header//////////////

	$('#section2').waypoint(function(direction) {
		 	if(direction == "down"){
       		$( ".small-header" ).css( {"top":"0px","opacity":"1"} );
       	}else{
       		$( ".small-header" ).css( {"top":"-120px","opacity":"0"} );
       	}
	});

	///////////Gallery Filter Effect//////////////

	$( ".portfolio .filter li" ).click(function() {
	  if(!$(this).hasClass("active")){
	  	$( ".portfolio .filter" ).find(".active").removeClass("active");
	  	$(this).addClass("active");
	  	var filter = $(this).attr("data-filter");
	  	$( ".gallery .tile" ).each(function() {	
	  		$(this).find("img").css({
	  				WebkitFilter : 'grayscale(0)',
					MozFilter    : 'grayscale(0)',
					MsFilter     : 'grayscale(0)',
					OFilter      : 'grayscale(0)',
					filter       : 'grayscale(0)',
					opacity		 : '1'
	  			});
	  			$(this).find("a:not('.close-btn')").css({
	  				display		: 'block'
	  			});
	  		if(filter != 'all' && !$(this).hasClass(filter)){
	  			$(this).find("img").css({
	  				WebkitFilter : 'grayscale(1)',
					MozFilter    : 'grayscale(1)',
					MsFilter     : 'grayscale(1)',
					OFilter      : 'grayscale(1)',
					filter       : 'grayscale(1)',
					opacity		 : '0.3'
	  			});
	  			$(this).find("a:not('.close-btn')").css({
	  				display		: 'none'
	  			});
	  		}
	  	});
	  }
	});

	///////////Anchor Smooth Scroll//////////////

	$(function() {
		var width = $( window ).width();
		var offset = 120;
		if(width < 768){
			offset = 0;
		}
		  $('header a[href*=#]:not([href=#])').click(function() {
		    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
		        || location.hostname == this.hostname) {

		      var target = $(this.hash);
		      target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
		      if (target.length) {
		        $('html,body').animate({
		          scrollTop: target.offset().top - offset
		        }, 500);
		        return false;
		      }
		    }
		  });
	});
});



	///////////Menu Tile Flip//////////////

	function AnimateRotate() {
	var i=0;
	$( "header .tile-flip .flipper" ).each(function() {
	    var $elem = $(this);
	    var startAngle = flip*180
	    var endAngle = startAngle + 180;
	    setTimeout(
		  function() 
		  {
		    $({deg: startAngle}).animate({deg: endAngle}, {
		        duration: 500,
		        step: function(now) {
		            $elem.css({
		                transform: 'rotateY(' + now + 'deg)'
		            });
		        }
		    });
		  }, 2000*i);
	    i+=1;
	    });
	flip+=1;
	}

	///////////Menu Tile Move//////////////

	function movePicture() {
	  $('.tile-move img').animate({left: '-50%'},2000,"easeInOutCubic").delay(500);
	  $('.tile-move img').animate({top: '-50%'},2000,"easeInOutCubic").delay(500);
	  $('.tile-move img').animate({left: '0%'},2000,"easeInOutCubic").delay(500);
	  $('.tile-move img').animate({top: '0%'},2000,"easeInOutCubic",movePicture).delay(500);
	}

